<template>
  <div class="app-container">
      <h1>酒店添加</h1><hr/>
        <el-form>
            <el-form-item label="酒店JSON数据,提交相同酒店编号则进行修改">
                <el-input type="textarea" v-model="hotel" cols="25" rows="25"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="add">提交</el-button>
                <el-button @click="reset">重置</el-button>
            </el-form-item>
        </el-form>
   </div>
</template>


<script>
import hotelApi from './api/hotel'

export default {
    data() {
      return {
          hotel:{
  "zkcode": "14441",
  "zkname": "这不是酒店",
  "zktype": "4",
  "provinceCode": "110000",
  "cityCode": "110100",
  "districtCode": "110102",
  "address": "阴间路",
  "intro": "这个酒店很一般",
  "route": "随便怎么走都能到",
  "logoData": "https://zkjd.oss-cn-beijing.aliyuncs.com/hotellogo/20220425103411.jpg",
  "hotelRoom": [{
    "zkcode": "10001",
    "roomcode": "5",
    "roomname": "21",
    "roomprice": "500",
    "status": "1"
  },{
    "zkcode": "10001",
    "roomcode": "6",
    "roomname": "22",
    "roomprice": "600",
    "status": "1"
  }]
}
      }
        
    },
    created() {
         this.hotel = JSON.stringify(this.hotel);
    },
   methods: {
        add() {
            var obj = JSON.parse(this.hotel);
            hotelApi.add(obj).
            then((response) => {
                 this.$message({
                  type: 'success',
                  message: '添加成功!'
               })
               this.$router.push({path:'/hotel-hotel'})
            })
        },
        reset(){
            this.hotel={};
        }
    }

}

</script>
